package com.shujia.mr.count;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MyCountReducer extends Reducer<Text, IntWritable,Text, IntWritable> {
    /**
     *
     * @param key 学生ID
     * @param values 同一个学生的各科成绩
     */
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        int totalScore = 0;
        // 循环遍历各科成绩再做累加
        for (IntWritable score : values) {
            int scoreInt = score.get();
            totalScore += scoreInt;
        }
        context.write(key,new IntWritable(totalScore));
    }
}
